local extension = Package:new("test5")
extension.extensionName = "aj_test"

local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["test5"] = "测试·五",
}
local ShuffleCount = fk.CreateTriggerSkill{
  name = "#ShuffleCount_trigger",
  global = true,
  mute = true,
  refresh_events = {fk.AfterDrawPileShuffle},
  can_refresh = Util.TrueFunc,
  on_refresh = function (self, event, target, player, data)
    player:setMark("ShuffleCount",player:getMark("ShuffleCount") + 1)
  end,
}

Fk:addSkill(ShuffleCount)

local kaituozhetongxie = General:new(extension, "test5__kaituozhetongxie", "test_xie", 3)

Fk:loadTranslationTable{
  ["test5__kaituozhetongxie"] = "开拓者·同谐",--名字
  ["#test5__kaituozhetongxie"] = "舞灯巡游",--称号
  ["designer:test5__kaituozhetongxie"] = "zuozhe",--作者
  ["cv:test5__kaituozhetongxie"] = "cv",--cv
  ["illustrator:test5__kaituozhetongxie"] = "huashi",--画师

  ['~test5__kaituozhetongxie'] = '还没…结束……',
}

local xiaowu = fk.CreateTriggerSkill{
name = "test5__xiaowu",
mute = true,
events = {fk.EventPhaseStart},
can_trigger = function(self, event, target, player, data)
  return target == player and player:hasSkill(self) and player.phase == Player.Start
end,
on_use = function(self, event, target, player, data)
  player.room:notifySkillInvoked(player, "test5__xiaowu")
  player:broadcastSkillInvoke("test5__xiaowu",math.random(1,2))
  for _, p in ipairs(player.room:getOtherPlayers(player, false)) do
   if table.find(p.buddy_list,function (t) return t == player.id end) == nil then
    p:addBuddy(player)
    player.room:addTableMark(player, "test5__xiaowu", p.id)
   end
  end
end,
refresh_events = {fk.TurnEnd},
can_refresh = function(self, event, target, player, data)
  return target == player and #player:getTableMark("test5__xiaowu") > 0
end,
on_refresh = function(self, event, target, player, data)
  for _, p in ipairs(player:getTableMark("test5__xiaowu")) do
    player.room:getPlayerById(p):removeBuddy(player)
  end
  player.room:setPlayerMark(player, "test5__xiaowu", 0)
end,
on_lose = function (self, player)
  for _, p in ipairs(player:getTableMark("test5__xiaowu")) do
    player.room:getPlayerById(p):removeBuddy(player)
   end
  player.room:setPlayerMark(player, "test5__xiaowu", 0)
end,
}

local xiaowu_use = fk.CreateTriggerSkill{
  name = "#test5__xiaowu_use",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes("test5__xiaowu") > 0 and not player.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:notifySkillInvoked(player, "test5__xiaowu")
    player:broadcastSkillInvoke("test5__xiaowu",math.random(3,4))
    local card_type,card_suit = {},{}
    for _, id in ipairs(player:getCardIds("h")) do
      table.insertIfNeed(card_type,Fk:getCardById(id).type)
    end
    if #card_type > 0 then
      player:drawCards(#card_type,"test5__xiaowu")
    end
    for _, id in ipairs(player:getCardIds("h")) do
      table.insertIfNeed(card_suit,Fk:getCardById(id).suit)
    end
    local n = player:getHandcardNum() - #card_suit
    if n > 0 then
      room:askForDiscard(player,n,n,false,"test5__xiaowu",false)
    else
      room:addPlayerMark(player,"test5__xiaowu-turn",1)
      if player:getMark("test5__xiaowu-turn") > 1 then
        room:askForDiscard(player,2,2,false,"test5__xiaowu",false)
        for _, p in ipairs(room:getAllPlayers()) do
          room:setPlayerMark(p, "@test5__jumu-turn", 0)
        end
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__xiaowu"] = "潇舞",
  [":test5__xiaowu"] = "准备阶段，你可以展示手牌直到回合结束，然后你本回合使用牌后，你摸手牌中类型数张牌，之后将手牌弃至其中花色数张。若你非本回合第一次未因此弃牌，你弃两张牌并重置“聚目”。",
  
  ["#test5__xiaowu_use"] = "潇舞",

  ["$test5__xiaowu1"] = "气氛已经烘托到位。",
  ["$test5__xiaowu2"] = "小心错过入场的最佳时机。",
  ["$test5__xiaowu3"] = "保持步调一致。",
  ["$test5__xiaowu4"] = "敬请期待。",
}

local jumu = fk.CreateTriggerSkill{
  name = "test5__jumu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    for _, move in ipairs(data) do
      if move.from and move.proposer and move.from == player.id and move.proposer == player.id 
      and move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and #move.moveInfo == 1 then
        local card = Fk:getCardById(move.moveInfo[1].cardId)
        self.cost_data = {card = card}
        return card.suit ~= Card.NoSuit and
        table.find(player.room:getAllPlayers(false), function (p)
          return not table.contains(p:getTableMark("@test5__jumu-turn"), card:getSuitString(true))
        end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = self.cost_data.card
    for _, p in ipairs(room:getAllPlayers(false)) do
      room:doIndicate(player.id, {p.id})
      room:addTableMark(p, "@test5__jumu-turn", card:getSuitString(true))
    end
  end,
}
local jumu_prohibit = fk.CreateProhibitSkill{
  name = "#test5__jumu_prohibit",
  prohibit_use = function(self, player, card)
    return card and table.contains(player:getTableMark("@test5__jumu-turn"), card:getSuitString(true))
  end,
}

Fk:loadTranslationTable{
  ["test5__jumu"] = "聚目",
  [":test5__jumu"] = "锁定技，当你弃置牌后，若数量为1，本回合所有角色不能使用与之花色相同的牌。",

  ["@test5__jumu-turn"] = "聚目",
  
  ["$test5__jumu1"] = "绝佳配合。",
  ["$test5__jumu2"] = "考验默契的时候。",
}

xiaowu:addRelatedSkill(xiaowu_use)
kaituozhetongxie:addSkill(xiaowu)
jumu:addRelatedSkill(jumu_prohibit)
kaituozhetongxie:addSkill(jumu)

local feicui = General:new(extension, "test5__feicui", "test_shi", 3,3,General.Female)

Fk:loadTranslationTable{
  ["test5__feicui"] = "翡翠",--名字
  ["#test5__feicui"] = "质生契运",--称号
  ["designer:test5__feicui"] = "zuozhe",--作者
  ["cv:test5__feicui"] = "cv",--cv
  ["illustrator:test5__feicui"] = "huashi",--画师

  ['~test5__feicui'] = '是我失算了…',
}

local yuqi = fk.CreateActiveSkill{
name = "test5__yuqi",
prompt = "#test5__yuqi",
can_use = function(self, player)
  return player:getHandcardNum() > 0 and player:usedSkillTimes("test5__yuqi",Player.HistoryPhase) == 0
end,
max_card_num = 1,
max_target_num = 1,
card_filter = function (self,to_select,selected,player)
  return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Player.Hand
end,
target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
  return to_select ~= player.id and #selected == 0
end,
feasible = function (self, selected, selected_cards, player)
  return #selected == 1 and #selected_cards == 1
end,
on_use = function(self, room, effect)
  local player = room:getPlayerById(effect.from)
  local target = room:getPlayerById(effect.tos[1])
  local card = Fk:getCardById(effect.cards[1])
  player:showCards(card)
  room:obtainCard(target,card,true,fk.ReasonGive,player.id,self.name)
  local card_names = U.getViewAsCardNames(target, "test5__yuqi", U.getAllCardNames("btd"), card)
  if #card_names > 0 then
    local use = U.askForUseVirtualCard(room,target,card_names,{card.id},"test5__yuqi",nil,false)
    if use and use.card.name ~= card.name then
      if target:getHandcardNum() > 0 and room:askForSkillInvoke(target,"test5__yuqi",nil,"#test5__yuqi-dis::"..player.id) then
        target:throwAllCards("h","test5__yuqi")
      else
        room:damage{
          from = player,
          to = target,
          damage = 2,
          skillName = "test5__yuqi",
        }
      end
    end
  end
end,
}


Fk:loadTranslationTable{
  ["test5__yuqi"] = "欲欺",
  [":test5__yuqi"] = "出牌阶段限一次，你可以展示一张手牌并交给一名角色，然后其须将此牌当任意非装备牌使用，若转化前后牌名不同，其弃置所有手牌（至少一张）或受到你的2点伤害。",
  
  ["#test5__yuqi"] = "欲欺：你可以展示一张手牌并交给一名角色",
  ["#test5__yuqi-dis"] = "欲欺：你须弃置所有手牌，或取消后受到%dest对你造成的2点伤害",

  ["$test5__yuqi1"] = "我这有笔更好的交易，要来听听看吗？",
  ["$test5__yuqi2"] = "欲望会创造机会。",
}

local yuqir = fk.CreateTriggerSkill{
  name = "test5__yuqir",
  anim_type = "offensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:usedSkillTimes("test5__yuqir",Player.HistoryRound) > 0 then return false end
    local kong = false
    for _, move in ipairs(data) do
      if move.from and move.from ~= player.id then
        local p = player.room:getPlayerById(move.from)
        if p.dead then return end
        for _, info in ipairs(move.moveInfo) do
          for _, Area in ipairs({Card.PlayerHand,Card.PlayerEquip,Card.PlayerJudge}) do
            if info.fromArea == Area and #p:getCardIds(Area) == 0 then
              self.cost_data = {p = p}
              kong = true
            end
          end
        end
      end
    end
    return kong
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local p = self.cost_data.p
    return room:askForSkillInvoke(player,self.name,nil,"#test5__yuqir::"..p.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = self.cost_data.p
    local n = p.hp - p:getHandcardNum()
    if p.hp > 0 and n > 0 then
      p:drawCards(n,"test5__yuqir")
    end
    room:setPlayerMark(player, "test5__yuqir-round", p.id)
    room:setPlayerMark(player, "@test5__yuqir-round", Fk:translate(p.general))
  end,
}

local yuqir_use = fk.CreateTriggerSkill{
  name = "#test5__yuqir_use",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and not target.dead 
    and player:hasSkill("test5__yuqir") and player:usedSkillTimes("#test5__yuqir_use") == 0 
    and player:getMark("test5__yuqir-round") == target.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
  player:broadcastSkillInvoke("test5__yuqir")
    player.room:useCard{
    from = player.id,
    tos = {{target.id}},
    card = Fk:cloneCard("slash"),
    extraUse = true,
    }
  end,
}

Fk:loadTranslationTable{
  ["test5__yuqir"] = "狱契",
  [":test5__yuqir"] = "每轮限一次，当一名其他角色失去一个区域内最后的牌后，你可令其将手牌摸至体力值，然后本轮每回合限一次，该角色使用牌后，你视为对其使用一张【杀】。",

  ["#test5__yuqir_use"] = "狱契",
  ["@test5__yuqir-round"] = "狱契",
  ["#test5__yuqir"] = "狱契：你可以令%dest将手牌摸至体力值",
  
  ["$test5__yuqir1"] = "协定一旦成立，就要负责到底哦。",
  ["$test5__yuqir2"] = "以此为据，也就再无反悔的余地…你我都是。",
}


feicui:addSkill(yuqi)
yuqir:addRelatedSkill(yuqir_use)
feicui:addSkill(yuqir)

local jiaoqiu = General:new(extension, "test5__jiaoqiu", "test_xu", 3)

Fk:loadTranslationTable{
  ["test5__jiaoqiu"] = "椒丘",--名字
  ["#test5__jiaoqiu"] = "鼎中捭阖",--称号
  ["designer:test5__jiaoqiu"] = "zuozhe",--作者
  ["cv:test5__jiaoqiu"] = "cv",--cv
  ["illustrator:test5__jiaoqiu"] = "huashi",--画师

  ['~test5__jiaoqiu'] = '对不起…将军……',
}

local yuanding = fk.CreateTriggerSkill{
  name = "test5__yuanding",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and Player.Judge == data.to
  end,
  on_use = function (self, event, target, player, data)
    return true
    --data.skipped = true
  end,
  on_acquire = function (self, player, is_start)
    for _, color in ipairs({Card.Red,Card.Black}) do
      local ids = table.filter(player:getCardIds("j"),function (id)
        return Fk:getCardById(id).color == color
      end)
      player.room:setPlayerMark(player,"@$test5__yuanding_"..(color == Card.Red and "red" or "black"),#ids == 0 and 0 or ids)
    end
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player,"@$test5__yuanding_red",0)
    player.room:setPlayerMark(player,"@$test5__yuanding_black",0)
  end,
}

local yuanding_trigger = fk.CreateTriggerSkill{
  name = "#test5__yuanding_trigger",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, _, target, player, data)
    if player:hasSkill("test5__yuanding") and player == target and data.card.trueName == "slash" and data.card.name ~= "fire__slash" then
      local black,red = 0,0
      for _, id in ipairs(player:getCardIds("j")) do
        local card = Fk:getCardById(id)
        if card.color == Card.Red then
          red = red + 1
        elseif card.color == Card.Black then
          black = black + 1 end
      end
      return red > black
    end
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke("test5__yuanding")
    local card = Fk:cloneCard("fire__slash", data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    if data.card:isVirtual() then
      card.subcards = data.card.subcards
    else
      card.id = data.card.id
    end
    card.skillNames = data.card.skillNames
    card.skillName = "test5__yuanding"
    player.room:sendLog{
      type = "#test5__yuanding_log",
      from = player.id,
      card = {data.card.id},
      arg = "test5__yuanding",
    }
    data.card = card
  end,
}

local yuanding_damage = fk.CreateTriggerSkill{
  name = "#test5__yuanding_damage",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = { fk.PreDamage },
  can_trigger = function(self, _, target, player, data)
    if player:hasSkill("test5__yuanding") and player == target and data.damageType ~= fk.FireDamage then
      local black,red = {},{}
      for _, id in ipairs(player:getCardIds("j")) do
        local card = Fk:getCardById(id)
        if card.color == Card.Red then table.insert(red,id) end
        if card.color == Card.Black then table.insert(black,id) end
      end
      return #red > #black
    end
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke("test5__yuanding")
    data.damageType = fk.FireDamage
  end,
}

local yuanding_judge = fk.CreateTriggerSkill{
  name = "#test5__yuanding_judge",
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill("test5__yuanding", true,true) then return false end
    for _, move in ipairs(data) do
      return (move.from and move.from == player.id and table.find(move.moveInfo,function (info)
        return info.fromArea == Player.Judge
      end)) or (move.to and move.to == player.id and move.toArea == Player.Judge)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, color in ipairs({Card.Red,Card.Black}) do
      local ids = table.filter(player:getCardIds("j"),function (id)
        return Fk:getCardById(id).color == color
      end)
      player.room:setPlayerMark(player,"@$test5__yuanding_"..(color == Card.Red and "red" or "black"),#ids == 0 and 0 or ids)
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__yuanding"] = "鸳鼎",
  [":test5__yuanding"] = "锁定技，你没有判定阶段且判定区中的红色/黑色牌称为“辣”/“清”，当“辣”数量为最多时，你的【杀】视为火【杀】且造成的伤害视为火焰伤害。",
  
  ["#test5__yuanding_trigger"] = "鸳鼎",
  ["#test5__yuanding_damage"] = "鸳鼎",
  ["@$test5__yuanding_red"] = "辣",
  ["@$test5__yuanding_black"] = "清",
  ["#test5__yuanding_log"] = "%arg：%from的%card视为火【杀】",

  ["$test5__yuanding1"] = "我还是更喜欢火上浇油。",
  ["$test5__yuanding2"] = "文火慢熬，抑或武火爆炒？",
}

local weilve = fk.CreateTriggerSkill{
  name = "test5__weilve",
  events = {fk.CardUseFinished,fk.Damage,fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and U.isPureCard(data.card)
    and table.contains({Card.Processing,Card.DiscardPile},player.room:getCardArea(data.card))
    and (#table.filter(player:getCardIds("j"),function (id) return Fk:getCardById(id).suit == data.card.suit end) < player.maxHp) then
      if event == fk.CardUseFinished then
        return data.card.type == Card.TypeBasic
      end
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil, "#test5__weilve:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(data.card,Player.Judge,player,fk.ReasonJustMove,self.name)
  end,
}

Fk:loadTranslationTable{
  ["test5__weilve"] = "味略",
  [":test5__weilve"] = "当你使用非转化基本牌后，或受到、造成非转化牌的伤害后，你可将这些牌置于判定区（每种花色数不超过你的体力上限）。",

  ["#test5__weilve"] = "味略：你可以将%arg置于判定区",
  ["@test5__weilve-turn"] = "味略",
  
  ["$test5__weilve1"] = "来都来了，不如吃过再走。",
  ["$test5__weilve2"] = "有福自然同享。",
}

local baihe = fk.CreateActiveSkill{
  name = "test5__baihe",
  prompt = "#test5__baihe",
  can_use = function(self, player)
    return player:usedSkillTimes("test5__baihe",Player.HistoryPhase) == 0 
    and table.find(player:getCardIds("j"),function (id) return Fk:getCardById(id).color == Card.Red end)
    and table.find(player:getCardIds("j"),function (id) return Fk:getCardById(id).color == Card.Black end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  interaction = function (self, player)
    local s = {}
    local n = 0
    local ask = {}
    for i, suit in ipairs({Card.Heart,Card.Spade,Card.Club,Card.Diamond}) do
      table.insert(s,table.filter(player:getCardIds("j"),function (id) return Fk:getCardById(id).suit == suit end))
      n = math.max(n,#s[i])
    end
    for _, suit in ipairs(s) do
     if #suit == n then
      table.insert(ask,Fk:getCardById(suit[1]):getSuitString())
     end
    end
    return UI.ComboBox{
      choices = ask,
    }
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local recast,use = {},{}
    for _, id in ipairs(player:getCardIds("j")) do
      local card = Fk:getCardById(id)
      if card:getSuitString() == self.interaction.data then
        table.insert(recast,id)
      elseif card.type == Card.TypeBasic or card:isCommonTrick() then
        table.insertIfNeed(use,card.name)
      end
    end
    room:recastCard(recast,player,"test5__baihe")
    local card_names = U.getViewAsCardNames(player, "test5__baihe", use)
    if #card_names > 0 then
      U.askForUseVirtualCard(room,player,card_names,nil,"test5__baihe",nil,false)
    end
  end,
  }
  
  Fk:loadTranslationTable{
    ["test5__baihe"] = "捭阖",
    [":test5__baihe"] = "出牌阶段限一次，若你的判定区同时有“辣”和“清”，你可重铸其中一种花色最多的牌并视为使用剩余牌中的一张基本牌或普通锦囊牌。",
    
    ["#test5__baihe"] = "捭阖：你可以重铸判定区一种花色的所有牌",
  
    ["$test5__baihe1"] = "三思而行，再思可矣。",
    ["$test5__baihe2"] = "与其伺机而动，不如一动不动。",
  }

yuanding:addRelatedSkill(yuanding_judge)
yuanding:addRelatedSkill(yuanding_damage)
yuanding:addRelatedSkill(yuanding_trigger)
jiaoqiu:addSkill(yuanding)
jiaoqiu:addSkill(weilve)
jiaoqiu:addSkill(baihe)


local lingsha = General:new(extension, "test5__lingsha", "test_shi", 3,3,General.Female)

Fk:loadTranslationTable{
  ["test5__lingsha"] = "灵砂",--名字
  ["#test5__lingsha"] = "卧香沉水",--称号
  ["designer:test5__lingsha"] = "zuozhe",--作者
  ["cv:test5__lingsha"] = "cv",--cv
  ["illustrator:test5__lingsha"] = "huashi",--画师

  ['~test5__lingsha'] = '烟消…火灭……',
}

local yunheng = fk.CreateActiveSkill{
  name = "test5__yunheng",
  prompt = "#test5__yunheng",
  can_use = function(self, player)
    return player:usedSkillTimes("test5__yunheng",Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = {}
    local chong = false
    repeat
      table.insert(cards,room:getNCards(1)[1])
      room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
      for _, suit in ipairs({Card.Heart,Card.Spade,Card.Club,Card.Diamond}) do
        if #table.filter(cards,function (id) return Fk:getCardById(id).suit == suit end) > 1 then
          chong = true
          break
        end
      end
      if chong then break end
      local all = {"#test5__yunheng_1","#test5__yunheng_2","#test5__yunheng_3"}
      local ask = table.clone(all)
      local players = table.filter(room:getAlivePlayers(),function (p)
        return not p:isNude()
      end)
      if #players == 0 or player:getMark("test5__yunheng-turn") ~= 0 then
        table.removeOne(ask,"#test5__yunheng_3")
      end
      local choice = room:askForChoice(player,ask,self.name,nil,nil,all)
      if choice == "#test5__yunheng_1" then
        room:obtainCard(player,cards,true,fk.ReasonJustMove,player.id,self.name)
        break
      elseif choice == "#test5__yunheng_3" then
        room:setPlayerMark(player,"test5__yunheng-turn",1)
        local t = room:getPlayerById(room:askForChoosePlayers(player,table.map(players,Util.IdMapper),1,1,"#test5__yunheng-dis",self.name,false)[1])
        local cid = room:askForCardChosen(player, t, "he", self.name,"#test5__yunheng-dis")
        room:throwCard({cid}, self.name, t, player)
        if room:askForSkillInvoke(t,self.name,nil,"#test5__yunheng-ask::"..player.id) then
          room:obtainCard(player,cards,true,fk.ReasonJustMove,player.id,self.name)
          break
        end
      end
      player:broadcastSkillInvoke("test5__yunheng")
    until chong
    if chong then
      cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
      local result = room:askForGuanxing(player, cards, nil, {0, 0}, self.name, true, {"Top", "toObtain"})
      if #result.top > 0 then
        room:moveCardTo(table.reverse(result.top), Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true, player.id)
      end
    end
  end,
}


Fk:loadTranslationTable{
  ["test5__yunheng"] = "氲横",
  [":test5__yunheng"] = "出牌阶段限一次，你可以展示牌堆顶一张牌，若花色与此前展示牌均不同，你选择一项：1.获得所有展示牌；2.重复此流程；3.弃置一名角色的一张牌，然后你执行其指定的“氲横”的一项（本项每回合只能被选择一次）。若你未获得展示牌，你将这些牌以任意顺序置于牌堆顶。",
  
  ["#test5__yunheng"] = "你可以发动【氲横】",
  ["#test5__yunheng_1"] = "获得所有展示牌",
  ["#test5__yunheng_2"] = "重复此流程",
  ["#test5__yunheng_3"] = "弃置一名角色的一张牌，然后你执行其指定的“氲横”的一项",

  ["#test5__yunheng-ask"] = "氲横：你可以令%dest获得所有展示牌，或取消后令其重复此流程",
  ["#test5__yunheng-dis"] = "氲横：弃置一名角色的一张牌",

  ["$test5__yunheng1"] = "炉香袅孤碧，云缕霏数千。",
  ["$test5__yunheng2"] = "金鳞燃犀，洞若观火。",
}

local xinliao = fk.CreateTriggerSkill{
  name = "test5__xinliao",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ps = table.map(table.filter(room:getOtherPlayers(player),function (p)
      return not p:isKongcheng()
    end),Util.IdMapper)
    local ids = table.filter(player:getCardIds("he"),function (id)
      return Fk:getCardById(id).suit == Card.Heart and not player:prohibitDiscard(id)
    end)
    if #ps == 0 or #ids ==0 then return end
    local pattern = ".|.|.|.|.|.|"..table.concat(ids,",")
    local p,c = room:askForChooseCardAndPlayers(player,ps,1,1,pattern,"#test5__xinliao")
    self.cost_data = {p = p[1],c = c}
    return #p > 0 and c
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = room:getPlayerById(self.cost_data.p)
    room:throwCard(self.cost_data.c,self.name,player,player)
    local card = Fk:getCardById(room:askForCard(p,1,1,false,self.name,false,nil,"#test5__xinliao-ask::"..player.id)[1])
    p:showCards(card)
    if card.suit == Card.Heart then
      if not p.chained then
        p:setChainState(true)
      end
      room:recover{
        who = p,
        num = 1,
        skillName = self.name,
        recoverBy = player,
      }
    else
      room:useCard{
        from = player.id,
        tos = {{p.id}},
        card = Fk:cloneCard("fire__slash"),
        extraUse = true,
      }
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__xinliao"] = "心缭",
  [":test5__xinliao"] = "结束阶段，你可弃置一张<font color=#CC3131><b>♥</b></font>牌并令一名其他角色展示一张手牌，若同为<font color=#CC3131><b>♥</b></font>，其横置并回复1点体力，否则你视为对其使用一张火【杀】。",

  ["#test5__xinliao"] = "心缭：你可弃置一张♥牌并令一名其他角色展示一张手牌",
  ["#test5__xinliao-ask"] = "心缭：你须展示一张牌，若花色为♥，你横置并回复1点体力，否则%dest视为对你使用一张火【杀】",
  
  ["$test5__xinliao1"] = "去污除秽，请。",
  ["$test5__xinliao2"] = "需要提提神吗？",
}


lingsha:addSkill(yunheng)
lingsha:addSkill(xinliao)

local xingqiri = General:new(extension, "test5__xingqiri", "test_xie", 3, 7)

Fk:loadTranslationTable{
  ["test5__xingqiri"] = "星期日",--名字
  ["#test5__xingqiri"] = "向星举目",--称号
  ["designer:test5__xingqiri"] = "zuozhe",--作者
  ["cv:test5__xingqiri"] = "cv",--cv
  ["illustrator:test5__xingqiri"] = "huashi",--画师

  ['~test5__xingqiri'] = '失约了……',
}

local xingsong = fk.CreateTriggerSkill{
  name = "test5__xingsong",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isKongcheng()
  end,
  on_cost = function (self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"),function (id)
      return not table.contains(DIY.GetShownCards(player),id)
    end)
    if #cards == 0 then return end
    local pattern = ".|.|.|.|.|.|"..table.concat(cards,",")
    local card = player.room:askForCard(player,1,1,false,self.name,true,pattern,"#test5__xingsong")
    if #card > 0 then
      self.cost_data = {c = card[1]}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = Fk:getCardById(self.cost_data.c)
    player.room:setCardMark(card,"@@test5__xingsong-inhand",1)
    DIY.ShowCards(player,card)
    if #player:getTableMark("@$test5__chuyuan") == 0 then
      player.room:addTableMark(player,"@$test5__chuyuan",card.id)
    end
  end,
  refresh_events = {fk.BeforeCardsMove, fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player.dead then return end
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId):getMark("@@test5__xingsong-inhand") > 0 then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard then
        local move_info = {}
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId):getMark("@@test5__xingsong-inhand") > 0 then
            table.insert(ids, info.cardId)
          else
            table.insert(move_info, info)
          end
        end
        if #ids > 0 then
          move.moveInfo = move_info
        end
      end
    end
    if #ids > 0 then
      player.room:sendLog{
        type = "#cancelDismantle",
        card = ids,
        arg = "test5__xingsong",
      }
    end
  end,
}

local xingsong_prohibit = fk.CreateProhibitSkill{
  name = "#test5__xingsong_prohibit",
  prohibit_discard = function(self, player, card)
    return card:getMark("@@test5__xingsong-inhand") > 0
  end,
}

local xingsong_use = fk.CreateTriggerSkill{
  name = "#test5__xingsong_use",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill("test5__xingsong") and not target.dead
  end,
  on_cost = function (self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"),function (id)
      local c = Fk:getCardById(id)
      return c:getMark("@@test5__xingsong-inhand") > 0 and c.trueName == data.card.trueName
    end)
    if #cards == 0 then return end
    local pattern = ".|.|.|.|.|.|"..table.concat(cards,",")
    local card = player.room:askForCard(player,1,1,false,"test5__xingsong",true,pattern,"#test5__xingsong-give::"..target.id..":"..Fk:translate(data.card.trueName))
    if #card > 0 then
      self.cost_data = {c = card[1]}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = self.cost_data.c
    player.room:obtainCard(target,card,true,fk.ReasonGive,player.id,"test5__xingsong")
    player:drawCards(1,"test5__xingsong")
    target:drawCards(1,"test5__xingsong")
  end,
}

Fk:loadTranslationTable{
  ["test5__xingsong"] = "星颂",
  [":test5__xingsong"] = "每轮开始时，你可以明置一张手牌且此牌不可被弃置。其他角色使用牌后，你可以将一张同名“星颂”牌交给其，然后你与其各摸一张牌。",
  
  ["#test5__xingsong_use"] = "星颂",
  ["#test5__xingsong_prohibit"] = "星颂",
  ["@@test5__xingsong-inhand"] = "星颂",
  ["#test5__xingsong"] = "星颂：你可以明置一张手牌",
  ["#test5__xingsong-give"] = "星颂：你可以交给 %dest 一张 %arg ，然后 %dest 与你各摸一张牌",

  ["#cancelDismantle"] = "%arg ： %card 不能被弃置",

  ["$test5__xingsong1"] = "以此身躯，与你同道，护你左右，领你远行。",
  ["$test5__xingsong2"] = "你所求的，便是你所得的。",
}

local zhuiqi = fk.CreateTriggerSkill{
  name = "test5__zhuiqi",
  anim_type = "support",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local players = table.filter(room:getAlivePlayers(),function (p)
      return not p:isAllNude()
    end)
    self.cost_data = {ps = players}
    return #players > 0 and room:askForSkillInvoke(player,self.name,nil,"#test5__zhuiqi::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local players = self.cost_data.ps
    local ps = room:askForChoosePlayers(target,table.map(players,Util.IdMapper),1,1,"#test5__zhuiqi-choose","test5__zhuiqi",false)
    if #ps > 0 then
      local t = room:getPlayerById(ps[1])
      local cid = room:askForCardChosen(target, t, "hej", self.name,"#test5__zhuiqi-obtain::"..t.id)
      room:obtainCard(target,cid,true,fk.ReasonJustMove,target.id,self.name)
      if data.from and #data.from:getCardIds("he") > 1 
      and #room:askForDiscard(data.from,2,2,true,self.name,true,nil,"#test5__zhuiqi-dis::"..player.id) > 1 then
        room:damage{
          to = player,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    end

  end,
}

Fk:loadTranslationTable{
  ["test5__zhuiqi"] = "坠祈",
  [":test5__zhuiqi"] = "当一名角色受到伤害后，你可以令其获得一名角色区域里的一张牌，若如此做，伤害来源可以弃置两张牌并令你受到1点无来源的雷电伤害。",

  ["#test5__zhuiqi"] = "坠祈：你可以令%dest获得一名角色区域里的一张牌",
  ["#test5__zhuiqi-choose"] = "坠祈：你选择一名角色区域里的一张牌获得之",
  ["#test5__zhuiqi-obtain"] = "坠祈：你选择 %dest 区域里的一张牌获得之",
  ["#test5__zhuiqi-dis"] = "坠祈：你可以弃置两张牌并令 %dest 受到1点无来源的雷电伤害",
  
  ["$test5__zhuiqi1"] = "尚不是止步的时候。",
  ["$test5__zhuiqi2"] = "纵使遍地荆棘，也当砥砺前行。",
}

local chuyuan = fk.CreateTriggerSkill{
  name = "test5__chuyuan",
  frequency = Skill.Wake,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    if (not player:hasSkill(self)) or (#player:getTableMark("@$test5__chuyuan") == 0) or (player:getMark("ShuffleCount") == 0) then return end
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          return table.contains(player:getTableMark("@$test5__chuyuan"),info.cardId)
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player,1)
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:isWounded() then
        room:recover{
          who = p,
          num = p.maxHp - p.hp,
          skillName = self.name,
          recoverBy = player,
        }
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__chuyuan"] = "初愿",
  [":test5__chuyuan"] = "觉醒技，当首张“星颂”牌进入弃牌堆后，若牌堆已洗牌，你增加1点体力上限并令所有角色回满体力值。",
  
  ["@$test5__chuyuan"] = "初愿",

  ["$test5__chuyuan1"] = "循此苦旅，得见群星。",
  ["$test5__chuyuan2"] = "自省后的瞭望，并非幻梦一场。",
}

xingsong:addRelatedSkill(xingsong_prohibit)
xingsong:addRelatedSkill(xingsong_use)
xingqiri:addSkill(xingsong)
xingqiri:addSkill(zhuiqi)
xingqiri:addSkill(chuyuan)

local wangguiren = General:new(extension, "test5__wangguiren", "test_xu", 3, 6, General.Female)

Fk:loadTranslationTable{
  ["test5__wangguiren"] = "忘归人",--名字
  ["#test5__wangguiren"] = "掷山破云",--称号
  ["designer:test5__wangguiren"] = "zuozhe",--作者
  ["cv:test5__wangguiren"] = "cv",--cv
  ["illustrator:test5__wangguiren"] = "huashi",--画师

  ['~test5__wangguiren'] = '命定如此么……',
}

local lihuan = fk.CreateViewAsSkill{
  name = "test5__lihuan",
  prompt = "#test5__lihuan",
  pattern = "jink,nullification",
  card_filter = Util.FalseFunc,
  interaction = function (self, player)
    local all_names = {"jink","nullification"}
    return U.CardNameBox {
      choices = U.getViewAsCardNames(player, "test5__lihuan", all_names),
      all_choices = all_names,
    }
  end,
  view_as = function(self, cards)
    if #cards ~= 0 then
      return nil
    end
    if Fk.all_card_types[self.interaction.data] == nil then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards_yc = table.filter(player:getCardIds("h"), function(id)
        return Fk:getCardById(id):getMark("test5__lihuan-inhand") == 0
      end)
    if #cards_yc > 0 then
      local pattern = ".|.|.|.|.|.|"..table.concat(cards_yc,",")
      local cards = room:askForCard(player, 1, 999, false, "test5__lihuan", true, pattern,"#test5__lihuan")
      if #cards > 0 then
        local card_names = {}
        player:showCards(cards)
        for _, id in ipairs(cards) do
          local card = Fk:getCardById(id)
          if table.contains(U.getAllCardNames("bt"),card.name) then
            table.insertIfNeed(card_names,card.name)
          end
        end
        if table.contains(card_names,use.card.name) then
          use.card = Fk:cloneCard(use.card.name)
          cards = table.filter(cards,function (id)
            return (room:getCardArea(id) == Card.PlayerHand) and (room:getCardOwner(id) == player)
          end)
          if #cards > 0 then
            room:recastCard(cards,player,"test5__lihuan")
          end
          return
        else
          U.askForUseVirtualCard(room,player,"fire_attack",nil,"test5__lihuan_use")
        end
      end
    end
    return self.name
  end,
  enabled_at_play = function(self, player)
    return table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id):getMark("test5__lihuan-inhand") == 0
        end) ~= nil and player:usedSkillTimes("test5__lihuan") < 2
  end,
  enabled_at_response = function (self, player, response)
    return table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id):getMark("test5__lihuan-inhand") == 0
        end) ~= nil and player:usedSkillTimes("test5__lihuan") < 2
  end,
}

local lihuan_view = fk.CreateActiveSkill{
  name = "test5__lihuan_view",
  mute = true,
  main_skill = lihuan,
  prompt = "#test5__lihuan",
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes("test5__lihuan") < 2 and 
    table.find(player:getCardIds("h"),function (id)
      return not player:cardVisible(id)
    end)
  end,
  min_card_num = 1,
  target_filter = Util.FalseFunc,
  card_filter = function(self, to_select, selected, player)
    return Fk:getCardById(to_select):getMark("test5__lihuan-inhand") == 0 and table.contains(player:getCardIds("h"),to_select)
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:notifySkillInvoked(player, "test5__lihuan")
    player:broadcastSkillInvoke("test5__lihuan")
    local card_names = {}
    player:showCards(effect.cards)
    for _, id in ipairs(effect.cards) do
      local card = Fk:getCardById(id)
      if table.contains(U.getAllCardNames("bt"),card.name) and U.getDefaultTargets(player,card) ~= nil then
        table.insertIfNeed(card_names,card.name)
      end
    end
    card_names = U.getViewAsCardNames(player, "test5__lihuan", card_names)
    if #card_names > 0 then
      U.askForUseVirtualCard(room,player,card_names,nil,"test5__lihuan",nil,false)
      local cards = table.filter(effect.cards,function (id)
        return (room:getCardArea(id) == Card.PlayerHand) and (room:getCardOwner(id) == player)
      end)
      if #cards > 0 then
        room:recastCard(cards,player,"test5__lihuan")
      end
    else
      U.askForUseVirtualCard(room,player,"fire_attack",nil,"test5__lihuan_use")
    end
  end,
}

--无懈可击的询问与使用牌的询问流程不同，无法通过触发技实现 视为使用 

local lihuan_damage = fk.CreateTriggerSkill{
  name = "#test5__lihuan_damage",
  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card and data.card.skillName == "test5__lihuan_use"
  end,
  on_refresh = function(self, event, target, player, data)
    data.card.extra_data = data.card.extra_data or {}
    data.card.extra_data.test5__lihuan_damage = data.card.extra_data.test5__lihuan_damage or {}
    table.insertIfNeed(data.card.extra_data.test5__lihuan_damage,target.id)
  end,
}

local lihuan_use = fk.CreateTriggerSkill{
  name = "#test5__lihuan_use",
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("test5__lihuan") --and data.card.skillName == "test5__lihuan_use"
    and data.card.extra_data and data.card.extra_data.test5__lihuan_damage
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if table.contains(data.card.extra_data.test5__lihuan_damage,p.id) then
        room:recover{
          who = p,
          num = 1,
          skillName = "test5__lihuan",
        }
      end
    end
  end,
}

local lihuan_visibility = fk.CreateVisibilitySkill{
  name = "#test5__lihuan_visibility",
  card_visible = function(self, player, card)
    if player:hasSkill("test5__lihuan") and table.contains(player:getCardIds("h"),card.id)
     and card:getMark("test5__lihuan-inhand") == 0 then
      return false
    end
  end
}

local lihuan_show = fk.CreateTriggerSkill{
  name = "#test5__lihuan_show",
  refresh_events = {fk.CardShown},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("test5__lihuan")
  end,
  on_refresh = function(self, event, target, player, data)
    for _, id in ipairs(data.cardIds) do
      player.room:setCardMark(Fk:getCardById(id),"test5__lihuan-inhand",1)
    end
  end,
}

local lihuan_dis = fk.CreateTriggerSkill{
  name = "#test5__lihuan_dis",
  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("test5__lihuan") and player.phase == Player.Discard
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local yc = player.maxHp - player.hp
    local cards_yc = table.filter(
      player:getCardIds(Player.Hand), function(id)
        local card = Fk:getCardById(id)
        return card:getMark("test5__lihuan-inhand") == 0
      end
    )
    local n = #cards_yc - yc
    if n > 0 then
      local dis
      if yc == 0 then
        dis = cards_yc
      else
        local pattern = ".|.|.|.|.|.|"..table.concat(cards_yc,",")        
        dis = room:askForCard(player, n, n, false, "phase_discard", false, pattern,"#test5__lihuan_discard:::"..n)
      end
      room:throwCard(dis,"phase_discard",player,player)
    end
  end,
}

local lihuan_validate = fk.CreateTriggerSkill{
  name = "#test5__lihuan_validate",
  visible = false,
  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@test5__lihuan") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(target,"@test5__lihuan",0)
    player.room:validateSkill(player,"test5__lihuan")
  end,
}

local recast = fk.CreateActiveSkill{
  name = "recast",
  prompt = "#recast",
  target_num = 0,
  can_use = function (self, player, card, extra_data)
    return not player:hasSkill("test5__lihuan")
  end,
  on_use = function(_, room, effect)
    room:recastCard(effect.cards, room:getPlayerById(effect.from))
  end
}
recast.cardSkill = true
Fk.skills["recast"] = recast


local lihuan_jin = function(self, player, card)
  if player:hasSkill("test5__lihuan") and table.contains(player:getCardIds("h"),card.id) and
  card:getMark("test5__lihuan-inhand") == 0 then
    return true
  end
end

local lihuan_maxcards = fk.CreateMaxCardsSkill{
  name = "#test5__lihuan_maxcards",
  exclude_from = lihuan_jin,
}

local lihuan_prohibit = fk.CreateProhibitSkill{
  name = "#test5__lihuan_prohibit",
  prohibit_use = lihuan_jin,
  prohibit_response = lihuan_jin,
  prohibit_discard = lihuan_jin,
}

lihuan:addRelatedSkill(lihuan_view)
lihuan:addRelatedSkill(lihuan_damage)
lihuan:addRelatedSkill(lihuan_use)
lihuan:addRelatedSkill(lihuan_dis)
lihuan:addRelatedSkill(lihuan_show)
lihuan:addRelatedSkill(lihuan_maxcards)
lihuan:addRelatedSkill(lihuan_visibility)
lihuan:addRelatedSkill(lihuan_prohibit)

Fk:loadTranslationTable{
  ["test5__lihuan"] = "离焕",
  [":test5__lihuan"] = "锁定技，你未展示过的手牌对你隐藏，且这些牌的手牌上限等于你已损失的体力值。每回合限两次，出牌阶段或当你需要抵消牌时，你可展示任意张隐藏手牌，视为使用或打出其中一张基本牌或普通锦囊牌并重铸展示牌。若未因此使用或打出牌，你可视为使用一张【火攻】，结算后受到此牌伤害的角色回复1点体力。",
  ["test5__lihuan_view"] = "离焕",
  [":test5__lihuan_view"] = "<font color=#CC3131><b>生命纵如微尘</b></font>",

  ["test5__lihuan_test"] = "可见",
  ["test5__lihuan_use"] = "离焕",
  ["#test5__lihuan_use"] = "离焕",
  ["#test5__lihuan_response"] = "离焕",
  ["#test5__lihuan"] = "离焕：你可以展示任意张隐藏手牌，视为使用或打出其中一张基本牌或普通锦囊牌并重铸展示牌",
  ["#test5__lihuan_discard"] = "离焕：你须弃置%arg张隐藏牌",
  ["@test5__lihuan"] = "离焕",

  ["$test5__lihuan1"] = "流云易散，长梦已醒。",
  ["$test5__lihuan2"] = "生命纵如微尘。",
  ["$test5__lihuan3"] = "只要彼此挂念，总有重逢之时。 ",
}

local xunji = fk.CreateTriggerSkill{
  name = "test5__xunji",
  events ={fk.HpChanged,fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getHandcardNum() > 1
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(player,2,2,false,self.name,true,nil,"#test5__xunji")
    self.cost_data = {cards = cards}
    return #cards > 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data.cards
    room:throwCard(cards, self.name, player, player)
    local n = Fk:getCardById(cards[1]).number - Fk:getCardById(cards[2]).number
    local m = (player.maxHp - player.hp)
    if math.abs(n) > m then
      if player:getHandcardNum() > 0 then
        player:showCards(player:getCardIds("h"))
      end
      player:drawCards(m,self.name)
      if player:hasSkill("test5__lihuan") then
        room:invalidateSkill(player,"test5__lihuan")
        room:setPlayerMark(target,"@test5__lihuan","#test5__xunji-nil")
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__xunji"] = "寻己",
  [":test5__xunji"] = "当你脱离濒死或体力值变化后，你可以将两张手牌置入弃牌堆，若点数相差大于X，你展示所有手牌，摸X张牌并令“离焕”失效至你的下个回合开始（X为已损失体力值）。",

  ["#test5__xunji"] = "寻己：你可以将两张手牌置入弃牌堆",
  ["#test5__xunji-nil"] = "失效",
  
  ["$test5__xunji1"] = "前尘旧梦，俱已往矣。",
  ["$test5__xunji2"] = "蜕变，总免不了挣脱过去。",
}
wangguiren:addSkill(lihuan_validate)
wangguiren:addSkill(lihuan)
wangguiren:addSkill(xunji)


local xunzhengfeixiao = General:new(extension, "test5__xunzhengfeixiao", "test_ex", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["test5__xunzhengfeixiao"] = "巡征飞霄",--名字
  ["#test5__xunzhengfeixiao"] = "飞镝追星",--称号
  ["designer:test5__xunzhengfeixiao"] = "zuozhe",--作者
  ["cv:test5__xunzhengfeixiao"] = "cv",--cv
  ["illustrator:test5__xunzhengfeixiao"] = "huashi",--画师

  ['~test5__xunzhengfeixiao'] = '各位…拜托了……',
}

local zhengdi = fk.CreateViewAsSkill{
  name = "test5__zhengdi",
  prompt = "#test5__zhengdi",
  pattern = "archery_attack",
  interaction = function (self, player)
    local all = {"$Hand","$Equip","$Judge"}
    local ask = {}
    for i, s in ipairs({"h","e","j"}) do
      if #player:getCardIds(s) > 0 and all[i] ~= player:getMark("test5__zhengdi-round") then
        table.insert(ask,all[i])
      end
    end
    return UI.ComboBox{
      choices = ask,
      all_choices = all,
    }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards,player)
    if self.interaction.data == nil then return end
    local all = {"h","e","j"}
    local ids
    for i, s in ipairs({"$Hand","$Equip","$Judge"}) do
      if self.interaction.data == s then
        ids = player:getCardIds(all[i])
        if #ids == 0 then return end
      end
    end
    local c = Fk:cloneCard("archery_attack")
    c.skillName = self.name
    c:addSubcards(ids)
    return c
  end,
  before_use = function (self, player, use)
    player.room:setPlayerMark(player,"test5__zhengdi-round",self.interaction.data)
  end,
  enabled_at_play = function (self, player)
    for _, s in ipairs({"h","e","j"}) do
      if #player:getCardIds(s) > 0 then return true end
    end
    return false
  end,
  enabled_at_response = function (self, player, response)
    if response then return end
    for _, s in ipairs({"h","e","j"}) do
      if #player:getCardIds(s) > 0 then return true end
    end
    return false
  end,
}
local zhengdi_use = fk.CreateTriggerSkill{  --方案二
  name = "#test5__zhengdi_use",
  mute = true,
  events = {fk.PreCardUse},
  can_trigger = function (self, event, target, player, data)
    return data.card.skillName == "test5__zhengdi" and target == player and player:hasSkill("test5__zhengdi")
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local tos = TargetGroup:getRealTargets(data.tos)
    if #tos > #data.card.subcards then
      for i, t in ipairs(tos) do
        if i > #data.card.subcards then
          TargetGroup:removeTarget(data.tos,t)
        end
      end
    end
  end,
  refresh_events = {fk.AfterCardUseDeclared}, --由于PreCardUse在牌移动前触发，摸牌需要在下一个时机触发，否则被转化的武器会计入距离计算
  can_refresh = function (self, event, target, player, data)
    return data.card.skillName == "test5__zhengdi" and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local tos = TargetGroup:getRealTargets(data.tos)
    if #tos == player:getAttackRange() then
      player:drawCards(player:getMark("@test5__zhengdi-round") + 1,"test5__zhengdi")
      player.room:addPlayerMark(player,"@test5__zhengdi-round")
    end
  end,
}

local zhengdi_attackrange = fk.CreateAttackRangeSkill{
  name = "#test5__zhengdi_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("test5__zhengdi") then
      return from:getMark("@test5__zhengdi-round")
    end
  end,
}

Fk:loadTranslationTable{
  ["test5__zhengdi"] = "征镝",
  [":test5__zhengdi"] = "你可以将本轮不同于上次发动“征镝”选择的区域的所有牌当作目标至多为选择牌数的【万箭齐发】使用，若你的攻击范围等于目标数，你摸一张牌，之后本轮你的攻击范围及“征镝”摸牌数+1。",

  ["#test5__zhengdi_use"] = "征镝",
  ["#test5__zhengdi"] = "征镝：你可以将本轮不同于上次发动“征镝”选择的区域的所有牌当作目标至多为选择牌数的【万箭齐发】使用",
  ["@test5__zhengdi-round"] = "征镝",

  ["$test5__zhengdi1"] = "我将，巡征追猎。",
  ["$test5__zhengdi2"] = "翾翔不坠，万载常胜！",
}

zhengdi:addRelatedSkill(zhengdi_attackrange)
zhengdi:addRelatedSkill(zhengdi_use)
xunzhengfeixiao:addSkill(zhengdi)

local daheita = General:new(extension, "test5__daheita", "test_shi", 3, 3, General.Female)

Fk:loadTranslationTable{
  ["test5__daheita"] = "大黑塔",--名字
  ["#test5__daheita"] = "视界来信",--称号
  ["designer:test5__daheita"] = "zuozhe",--作者
  ["cv:test5__daheita"] = "cv",--cv
  ["illustrator:test5__daheita"] = "huashi",--画师

  ['~test5__daheita'] = '我还会回来……',
}

local jingying = fk.CreateTriggerSkill{
  name = "test5__jingying",
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ps = table.filter(room:getOtherPlayers(player),function (p)
      return not p:isKongcheng()
    end)
    if #ps == 0 then return end
    local ts = room:askForChoosePlayers(player,table.map(ps,Util.IdMapper),1,999,"#test5__jingying","test5__jingying")
    self.cost_data = {ts = ts}
    return #ts > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local red,black = {},{}
    for _, t in ipairs(room:getOtherPlayers(player)) do
      if table.contains(self.cost_data.ts,t.id) then
        local c = Fk:getCardById(room:askForCard(t,1,1,false,self.name,false,nil,"#test5__jingying-show")[1])
        t:showCards(c)
        if c.color == Card.Red then
          table.insert(red,t.id)
        elseif c.color == Card.Black then
          table.insert(black,t.id)
        end
      end
    end
    if player:isNude() then return end
    local use_data = {
      skillName = self.name,
      extra_data = {
        red = red,
        black = black,
      },
    }
    local _, ret = room:askForUseActiveSkill(player, "#test5__jingying_choose", "#test5__jingying-slash", true, use_data,false)
    if ret and ret.targets and ret.cards then
      local card = Fk:cloneCard("ice__slash")
      card.skillName = self.name
      card:addSubcards(ret.cards)
      room:useCard{
        from = player.id,
        tos = table.map(ret.targets, function(p) return {p} end),
        card = card,
        skillName = self.name,
      }
    end
  end,
}

local jingying_use = fk.CreateTriggerSkill{   
  name = "#test5__jingying_use",
  mute = true,
  events = {fk.PreCardEffect},
  can_trigger = function (self, event, target, player, data)
    if data.card.skillName == "test5__jingying" and target == player then
      local use = player.room.logic:getCurrentEvent().parent.data[1]
      use.extra_data = use.extra_data or {}
      return use.extra_data.test5__jingying
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    return true
  end,
  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return data.card and data.card.skillName == "test5__jingying" and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local use = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1]
    use.extra_data = use.extra_data or {}
    use.extra_data.test5__jingying = true
  end,
}

local jingying_choose = fk.CreateActiveSkill{
  name = "#test5__jingying_choose",
  mute = true,
  interaction = function (self, player)
    local all = {"black","red"}
    local ask = {}
    for _, id in ipairs(player:getCardIds("he")) do
      table.insertIfNeed(ask,Fk:getCardById(id):getColorString())
    end
    return UI.ComboBox{
      choices = ask,
      all_choices = all,
    }
  end,
  card_filter = function(self, to_select, selected)
    local n
    if self.interaction.data == nil then
      n = 1
    else
      n = self.interaction.data == "red" and #self.extra_data.red or #self.extra_data.black
    end
    return #selected < n and Fk:getCardById(to_select):getColorString() == self.interaction.data
  end,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    --目标数要等于选牌数，目标展示牌要和选择牌颜色相同，目标能被冰杀指定
    if self.interaction.data == nil then return false end
    return #selected < #selected_cards and
    table.contains((self.interaction.data == "red" and self.extra_data.red or self.extra_data.black),to_select)
    and player:canUseTo(Fk:cloneCard("ice__slash"),Fk:currentRoom():getPlayerById(to_select),{bypass_distances = true,bypass_times = true})
  end,
  feasible = function (self, selected, selected_cards, player)
    return #selected > 0 and #selected == #selected_cards and self.interaction.data
  end,
}

Fk:loadTranslationTable{
["test5__jingying"] = "镜影",
[":test5__jingying"] = "出牌阶段开始时，你可以令任意名其他角色依次展示一张手牌，然后你可以将任意张同色牌当冰【杀】对等量名此颜色牌的展示者依次使用直到造成伤害。",

["#test5__jingying_choose"] = "镜影",
["#test5__jingying"] = "镜影：你可以令任意名其他角色依次展示一张手牌",
["#test5__jingying-show"] = "镜影：你须展示一张手牌",
["#test5__jingying-slash"] = "镜影：你可以将任意张同色牌当冰【杀】对等量名此颜色牌的展示者依次使用直到造成伤害",

["$test5__jingying1"] = "好奇心可是很危险的。",
["$test5__jingying2"] = "全部点亮就好了。",
}

local jiezhi = fk.CreateTriggerSkill{
  name = "test5__jiezhi",
  events ={fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player,1,1,true,self.name,true,nil,"#test5__jiezhi",true)
    self.cost_data = {cards = cards}
    return #cards > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(self.cost_data.cards[1])
    while true do
      room:throwCard(card,self.name,player,player)
      local ids = table.filter(player:getTableMark("@$test5__jiezhi-turn"),function (id)
        local c = Fk:getCardById(id)
        return c.type ~= card.type and c.color ~= card.color
      end)
      if #ids > 0 then
        room:obtainCard(player,ids,true,fk.ReasonJustMove,player.id,self.name)
      end
      if #ids > 1 then
        local c = room:askForDiscard(player,1,1,true,self.name,true,nil,"#test5__jiezhi")
        if #c > 0 then
          room:notifySkillInvoked(player, "test5__jiezhi")
          player:broadcastSkillInvoke("test5__jiezhi")
          card = Fk:getCardById(c[1])
          room:addPlayerMark(player,MarkEnum.AddMaxCardsInTurn)
          room:addPlayerMark(player,"@test5__jiezhi_num-turn")
        else
          break
        end
      else
        break
      end
    end
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self, true) and player.phase ~= Player.NotActive then --回合内
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.room.discard_pile, info.cardId) then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = player:getTableMark("@$test5__jiezhi-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(room.discard_pile, info.cardId) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
          table.removeOne(ids, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "@$test5__jiezhi-turn", ids)
  end,
}

Fk:loadTranslationTable{
["test5__jiezhi"] = "解桎",
[":test5__jiezhi"] = "出牌阶段结束时，你可以弃置一张牌，然后获得与此牌类型颜色均不同且于本回合因弃置进入弃牌堆的牌。若获得牌数大于1，你可重复此流程并令你本回合手牌上限+1。",

["#test5__jiezhi"] = "解桎：你可以弃置一张牌，然后获得与此牌类型颜色均不同且于本回合因弃置进入弃牌堆的牌",
["@test5__jiezhi_num-turn"] = "解桎",
["@$test5__jiezhi-turn"] = "解桎",

["$test5__jiezhi1"] = "这就结束了？这就满足了？",
["$test5__jiezhi2"] = "科学没有界限，我更没有。",
}

jingying:addRelatedSkill(jingying_use)
Fk:addSkill(jingying_choose)
daheita:addSkill(jingying)
daheita:addSkill(jiezhi)


local feixiao = General:new(extension, "test5__feixiao", "test_lie", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["test5__feixiao"] = "飞霄",--名字
  ["#test5__feixiao"] = "飙驭霆击",--称号
  ["designer:test5__feixiao"] = "zuozhe",--作者
  ["cv:test5__feixiao"] = "cv",--cv
  ["illustrator:test5__feixiao"] = "huashi",--画师

  ['~test5__feixiao'] = '各位…拜托了……',
}

local yueguan = fk.CreateActiveSkill{
  name = "test5__yueguan",
  prompt = "#test5__yueguan",
  can_use = function(self, player)
    return player:usedSkillTimes("test5__yueguan",Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local data = effect.extra_data or {}
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = Fk:getCardById(room:askForCardChosen(player,target,"h",self.name))
    room:recastCard({card.id},target,"test5__yueguan")
    if card.suit == Card.NoSuit then return end
    local suits = player:getTableMark("@test5__yueguan-turn")
    if table.insertIfNeed(suits, card:getSuitString(true)) then
      room:setPlayerMark(player, "@test5__yueguan-turn", suits)
      if room:getCardArea(card) ~= Card.DiscardPile then return end
      local all_choices = {
        "WeaponSlot",
        "ArmorSlot",
        "DefensiveRideSlot",
        "OffensiveRideSlot",
        "TreasureSlot"
      }
      local subtypes = {
        Card.SubtypeWeapon,
        Card.SubtypeArmor,
        Card.SubtypeDefensiveRide,
        Card.SubtypeOffensiveRide,
        Card.SubtypeTreasure
      }
      local choices = {}
      for i = 1, 5, 1 do
        if #player:getAvailableEquipSlots(subtypes[i]) > 0 and                  -- 判断空置装备栏   不是钺贯牌
          not table.find(player:getEquipments(subtypes[i]),function (id)        -- not（有该副类型的装备牌且拥有这张牌的技能）
            local c = Fk:getCardById(id)  ---@cast c EquipCard
            return c:getMark("test5__yueguan") ~= 0 or (table.find(c:getEquipSkills(player),function (s)
              return player:hasSkill(s,true)
            end) ~= nil)
          end)  then
          table.insert(choices, all_choices[i])
        end
      end
      local choice
      if #choices > 0 then
        table.insert(all_choices,"#test5__yueguan_slash::"..target.id)
        table.insert(choices,"#test5__yueguan_slash::"..target.id)
        choice = room:askForChoice(player,choices,self.name,"#test5__yueguan-ask::"..target.id..":"..card:toLogString(),false,all_choices)
        if choice ~= "#test5__yueguan_slash::"..target.id then
          local mapper = {
            [Player.WeaponSlot] = "weapon",
            [Player.ArmorSlot] = "armor",
            [Player.OffensiveRideSlot] = "offensive_ride",
            [Player.DefensiveRideSlot] = "defensive_ride",
            [Player.TreasureSlot] = "treasure",
          }
          if card:getSubtypeString() ~= mapper[choice] then
            room:setCardMark(card, "test5__yueguan", mapper[choice])
            Fk:filterCard(card.id,player)
          end
          room:moveCards{
            ids = {card.id}, 
            from = nil, 
            to = player.id,
            toArea = Card.PlayerEquip,
            moveReason = fk.ReasonPut,
            skillName = self.name,
            proposer = player.id,
          }
        end
      end
      if #choices == 0 or choice == "#test5__yueguan_slash::"..target.id then
        local c = Fk:cloneCard("slash")
        c.skillName = (data.test5__tianji and "test5__tianji" or "test5__yueguan")
        room:useCard{
          from = player.id,
          tos = {{target.id}},
          card = c,
          skillName = data.test5__tianji and "test5__tianji" or "test5__yueguan"
        }
      end
    end
  end,
}

local yueguan_move = fk.CreateTriggerSkill{
  name = "#test5__yueguan_move",
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.Processing then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId, true):getMark("test5__yueguan") ~= 0 then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.Processing then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            player.room:setCardMark(Fk:getCardById(info.cardId, true),"test5__yueguan", 0)
          end
        end
      end
    end
  end,
}


local yueguan_filter = fk.CreateFilterSkill{
  name = "#test5__yueguan_filter",
  card_filter = function(self, to_select, player, isJudgeEvent)
    return to_select:getMark("test5__yueguan") ~= 0
  end,
  view_as = function(self, to_select, player)
    return Fk:cloneCard(to_select:getMark("test5__yueguan").."__yueguan", to_select.suit, to_select.number)
  end,
}
  
Fk:loadTranslationTable{
  ["test5__yueguan"] = "钺贯",
  [":test5__yueguan"] = "出牌阶段限一次，你可重铸一名其他角色的一张手牌，若此牌花色本回合首次因此技能进入弃牌堆，你选择一项：1.将此牌置入你的空装备栏（副类型不同则无技能效果）；2.视为对其使用一张【杀】。",
  
  ["#test5__yueguan_filter"] = "钺贯",
  ["#test5__yueguan"] = "钺贯：你可以选择一名其他角色的一张手牌，令其重铸之",
  ["#test5__yueguan-ask"] = "钺贯：你可以将 %arg 置入你的空装备栏或视为对 %dest 使用一张【杀】",
  ["#test5__yueguan_slash"] = "视为对 %dest 使用一张【杀】",
  ["@test5__yueguan-turn"] = "钺贯",

  ["$test5__yueguan1"] = "不避，不悔。",
  ["$test5__yueguan2"] = "无惧，无畏。",
}

local tianji = fk.CreateTriggerSkill{
  name = "test5__tianji",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill("test5__tianji") and player:usedSkillTimes("test5__tianji",Player.HistoryRound) == 0
    and #player:getCardIds("e") > 0 and #player:getCardIds("h") > 0) then return end
    for _, move in ipairs(data) do
      return move.from and move.from == player.id and table.find(move.moveInfo,function (info)
        return info.fromArea == Card.PlayerEquip
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#test5__tianji:::"..#player:getCardIds("e"))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:throwAllCards("h",self.name)
    for i = 1, #player:getCardIds("e"), 1 do
      if table.find(room:getOtherPlayers(player),function (p)
        return not p:isKongcheng()
      end) then
        local t, use = room:askForUseActiveSkill(player,"test5__yueguan",nil,false,{skipUse = true})
        if t and use then
          yueguan:onUse(room,{
            from = player.id,
            tos = use.targets,
            cards = nil,
            extra_data = {
              test5__tianji = true --需要手动传递extra_data
            },
          })
        end
      else
        break
      end
    end
    if player:getMark("@@test5__zaohuang") > 0 then
      player:setSkillUseHistory("test5__tianji", 0, Player.HistoryRound)
    end
  end,
}

local tianji_damage = fk.CreateTriggerSkill{
  name = "#test5__tianji_damage",
  mute = true,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("test5__tianji") and data.card and data.card.skillName == "test5__tianji"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1,"test5__tianji")
  end,
}

Fk:loadTranslationTable{
  ["test5__tianji"] = "天击",
  [":test5__tianji"] = "每轮限一次，当你失去装备区的牌后，你可以弃置所有手牌并发动X次“钺贯”（X为你装备区的牌数），且你每因此造成伤害后摸一张牌。",
  
  ["#test5__tianji"] = "天击：你可以弃置所有手牌并发动 %arg 次“钺贯”",

  ["$test5__tianji1"] = "我将，巡征追猎。",
  ["$test5__tianji2"] = "天击之责，至死方休。",
}

local zaohuang = fk.CreateActiveSkill{
  name = "test5__zaohuang",
  frequency = Skill.Limited,
  prompt = "#test5__zaohuang",
  can_use = function(self, player)
    return player:usedSkillTimes("test5__zaohuang",Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setPlayerMark(player,"@@test5__zaohuang",1)
    room:changeMaxHp(player,-1)
    room:handleAddLoseSkills(player,"test5__zaohuang_view","test5__zaohuang",true)
  end,
}

local zaohuang_end = fk.CreateTriggerSkill{
  name = "#test5__zaohuang_end",
  visible = false,
  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@test5__zaohuang") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player,"@@test5__zaohuang",0)
    player.room:handleAddLoseSkills(player,"-test5__zaohuang_view","test5__zaohuang",true)
  end,
}

local zaohuang_kill = fk.CreateTriggerSkill{
  name = "#test5__zaohuang_kill",
  mute = true,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("test5__zaohuang") and data.damage.from and data.damage.from == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:setSkillUseHistory("test5__zaohuang",0,Player.HistoryGame)
    player.room:notifySkillInvoked(player, "test5__zaohuang","control")
    player:broadcastSkillInvoke("test5__zaohuang")
  end,
}

local zaohuang_filter = fk.CreateFilterSkill{ --由于“钺贯”牌被视为了装备，在这里添加如手牌般使用，会让这些牌被当装备使用
  name = "#test5__zaohuang_filter",
  handly_cards = function (self, player)
    if player:hasSkill("test5__zaohuang") and player:getMark("@@test5__zaohuang") > 0 then
      return table.filter(player:getCardIds("e"),function (id)
        local card = Fk:getCardById(id,true)
        return card.type ~= Card.TypeEquip
      end)
    end
  end,
}

local zaohuang_view = fk.CreateViewAsSkill{
  name = "test5__zaohuang_view",
  --main_skill = zaohuang,
  prompt = "#test5__zaohuang_view",
  pattern = ".",
  card_filter = function (self, to_select, selected, player)
    return #selected == 0 and table.contains(player:getCardIds("e"),to_select) and Fk:getCardById(to_select,true).type ~= Card.TypeEquip
  end,
  view_as = function(self, cards, player)
    if #cards ~= 1 then return nil end
    return Fk:getCardById(cards[1],true)
  end,
  before_use = function (self, player, use)
    player.room:setCardMark(use.card,"test5__yueguan",0)
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@@test5__zaohuang") > 0 and table.find(player:getCardIds("e"),function (id)
      local card = Fk:getCardById(id,true)
      if Fk.currentResponsePattern == nil then
        return card.type ~= Card.TypeEquip and player:canUse(card)
      else
        return card.type ~= Card.TypeEquip and Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end)
  end,
  enabled_at_response = function (self, player, response)
    return not response and player:getMark("@@test5__zaohuang") > 0 and table.find(player:getCardIds("e"),function (id)
      local card = Fk:getCardById(id,true)
      if Fk.currentResponsePattern == nil then
        return card.type ~= Card.TypeEquip and player:canUse(card)
      else
        return card.type ~= Card.TypeEquip and Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end)
  end,
}
  
Fk:loadTranslationTable{
  ["test5__zaohuang"] = "凿荒",
  [":test5__zaohuang"] = "限定技，出牌阶段，你可以减1点体力上限，然后直到你的下回合开始前，你可以如手牌般使用装备区中的非装备牌，且在每次“天击”结算后重置“天击”次数。你完成击杀后复原此技能。",
  
  ["test5__zaohuang_view"] = "凿荒",
  [":test5__zaohuang_view"] = "你可以使用装备区中的非装备牌。",

  ["#test5__zaohuang_filter"] = "凿荒",
  ["#test5__zaohuang_view"] = "凿荒：你可以如手牌般使用装备区中的非装备牌",
  ["#test5__zaohuang"] = "凿荒：你可以减1点体力上限，然后直到你的下回合开始前，你可以如手牌般使用装备区中的非装备牌，且在每次“天击”结算后重置“天击”次数",
  ["@@test5__zaohuang"] = "凿荒",

  ["$test5__zaohuang1"] = "大捷，已定！",
  ["$test5__zaohuang2"] = "翾翔不坠，万载常胜！",
}


yueguan:addRelatedSkill(yueguan_move)
yueguan:addRelatedSkill(yueguan_filter)
feixiao:addSkill(yueguan)
tianji:addRelatedSkill(tianji_damage)
feixiao:addSkill(tianji)
feixiao:addSkill(zaohuang_end)
zaohuang:addRelatedSkill(zaohuang_view)
zaohuang:addRelatedSkill(zaohuang_kill)
feixiao:addSkill(zaohuang)


return extension